import {formatNull} from './common.js'

export function getToken() {
  return localStorage.getItem('token')
}
export function storeUserInfo(data) {
  localStorage.setItem('intentionalExam',formatNull(data.intentionalExam))
  localStorage.setItem('intentionalExamId',formatNull(data.intentionalExamId))
  localStorage.setItem('name',formatNull(data.name))
  localStorage.setItem('nickName',formatNull(data.nickName))
  localStorage.setItem('mobile',formatNull(data.mobile))
  localStorage.setItem('avatarPicUrl',formatNull(data.avatarPicUrl))
  localStorage.setItem('token',formatNull(data.sessionKey))
  localStorage.setItem('id',formatNull(data.id))
  localStorage.setItem('provinceId',formatNull(data.provinceId))
}

export function removeUserInfo() {
  localStorage.removeItem('name')
  localStorage.removeItem('nickName')
  localStorage.removeItem('mobile')
  localStorage.removeItem('avatarPicUrl')
  localStorage.removeItem('token')
  localStorage.removeItem('id')
  localStorage.removeItem('intentionalExam')
  localStorage.removeItem('intentionalExamId')
  localStorage.removeItem('provinceId')
}

export function getUserId() {
  return localStorage.getItem('id')
}

export function isLogin() {
  let token = localStorage.getItem('token')
  return token != null
}
